Printing the Curve to the User's Default Printer
Once you've created a shape, it's easy to print it using QuickDraw GX printing. Most of the functions provided with the printing part of QuickDraw GX allow you to provide sophisticated printing options to your user. These options are discussed in Chapter 8, "Printing."For simplicity, this example does not present the user with any options--that is, it doesn't display any of the QuickDraw GX printing dialog boxes. Instead, it implements a simple Print One Copy command--it prints one copy of the curve shape, using a single page, to the default printer already chosen by
the user.Before you can use the printing part of QuickDraw GX, you need to initialize it using the
GXInitPrinting
function:
GXInitPrinting();In a real application, you would check for errors after this call to the
- Note
- You must have a graphics client heap before you call this function. Typically, you call this function when initializing your application, immediately after creating a graphics client heap. After you've called this function, you cannot call any Macintosh Printing Manager functions until you've exited from QuickDraw GX printing using the
GXExitPrinting
function.![]()
GXInitPrinting
function, as described in Chapter 8, "Printing."With QuickDraw GX, every document has an associated job object that stores information about how to print the document. For the purposes of this example, the curve shape represents a simple document to be printed, so you need to declare a job object reference variable and then create a new print job object by calling the
GXNewJob
function:
gxJob aPrintJob; GXNewJob(&aPrintJob);Once you have a print job object, there are a number of ways you can print
your shapes with QuickDraw GX. One of the simplest ways is to collect all
of the shapes on a single page into a picture shape--a shape that contains collections of other shapes--and then use theGXPrintPage
function to print
the picture shape.To create a picture shape, you first declare a shape object reference variable, as in this declaration:
gxShape aPage;and then you can create the picture shape object using theGXNewShape
function:
aPage = GXNewShape(gxPictureType);After this call to theGXNewShape
function, theaPage
variable contains a reference to a new picture shape object. You can add your curve shape to
the picture shape using theGXSetPicture
function:
GXSetPicture(aPage, 1, &aCurveShape, nil, nil, nil);The geometry of a picture shape object contains a list of references to other shapes. TheGXSetPicture
function allows you to specify the list of references and copies the references you specify into the geometry property of the picture shape object.
After the above call to the
- The first parameter to
GXSetPicture
specifies the picture shape.- The second parameter specifies how many references to copy into the picture's geometry.
- The third parameter specifies the references.
- The fourth, fifth, and sixth parameters specify overriding information and are not used in this example.
GXSetPicture
function, the picture shape referenced by theaShape
variable has a geometry that contains a reference to exactly one shape--your curve shape.Now that you have a picture shape representing the page of shapes you want to print, you are ready to print the page using the
GXPrintPage
function. To begin printing, you call theGXStartJob
function, then you call theGXPrintPage
function once for every page you want to print, and finally you call theGXFinishJob
function.Here is an example:
GXStartJob(aPrintJob, "\p Rotated Gray Curve ", 1); GXPrintPage(aPrintJob, 1, GXGetJobFormat(aPrintJob, 1), aPage); GXFinishJob(aPrintJob);TheGXStartJob
function begins the print job:
The
- The first parameter specifies the document's job object.
- The second parameter specifies the name of the document to be printed.
- The third parameter specifies the number of pages to be printed.
GXPrintPage
function prints one page of a document:
The
- The first parameter specifies the document's job object.
- The second parameter specifies the page number being printed.
- The third parameter species the format of the page. (Note that this example calls the
GXGetJobFormat
function to get the format of the page. This call toGXGetJobFormat
returns a reference to the default format object associated with the job object. When you created the job object usingGXNewJob
, QuickDraw GX automatically created a default format object for you.)- The fourth parameter specifies a picture shape that contains the contents of the page.
GXFinishJob
function notifies QuickDraw GX that printing is complete.Once you've finish printing, dispose of the objects you used to print the document. In this case, dispose of the picture shape:
GXDisposeShape(aPage);When you no longer need your job object (typically, when your user closes a document), dispose of it also:
GXDisposeJob(aPrintJob);When you no longer need to use QuickDraw GX printing, you can exit from it using theGXExitPrinting
function:
GXExitPrinting();Also, whenever you are finished using your curve shape, dispose of it as well:
GXDisposeShape(aCurveShape);
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help